Repository navigation
Conversation
The input schema was generated from rawIn, which drops default values from optional props and tuple elements, so defaults set with `key: "string = 'x'"` never reached Standard JSON Schema consumers. Convert the type itself with io: "in" instead, converting a morph's input directly and allowing undeclared keys that would be deleted, so the result matches rawIn apart from the defaults. Fixes arktypeio#1575
Contributor
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This reviews the rework of ~standard.jsonSchema.input to convert the full type with a new internal io: "in" context flag instead of rawIn, so defaults survive into the input schema.
- Input conversion via
io: "in"—BaseRoot["~standard"].jsonSchema.inputnow converts the type itself withio: "in"(ark/schema/roots/root.ts:112), andMorphNode.innerToJsonSchemaconvertsdeclaredIn ?? inner.indirectly under that flag (ark/schema/roots/morph.ts:207), preserving defaults arawInreduce would have dropped. Verified against base: a nested object default inside a morph input now appears in the input schema. - Undeclared-key parity —
StructureNodeonly emitsadditionalProperties: falseforonUndeclaredKey("delete")outsideio: "in"(ark/schema/structure/structure.ts:921), keepingrawIn's input behavior. Confirmed unchanged versus base for a transform-backeddelete. - Tests — five new cases in
ark/type/__tests__/standardSchema.test.tscover object/thunk/tuple defaults, defaults inside a morph's input,onUndeclaredKey("delete")input vs output, and morph-fallback parity. Fullpnpm test(1795 passing) and the targeted schema suites pass locally.
The union-of-unit-branches case flagged in the description (type("true").pipe(() => 1).or("false") now emitting { enum: [true, false] } instead of { type: "boolean" }) produces a valid, equivalent schema for both targets, so I don't think it warrants a special case.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
ssalbdivad
added a commit
that referenced
this pull request
Oct 22, 2026
~standard.jsonSchema.input converted the Type's rawIn, which strips defaults, so an input schema never had a key's `default` (#1575). Zod and Valibot both write them, and consumers like form generators read them. This ports external PR #1695's approach, written against main's ark/schema JSON Schema code, to featherduster's ark/sets toJsonSchema.ts: - ToJsonSchema.Context gains `io?: "in"`, which toStandardJsonSchema sets for `input` and which mergeToJsonSchemaConfigs carries like any option. - `input` converts the Type itself rather than rawIn, so prop and tuple defaults are written by the existing writeDefault paths. - With io "in", a morph writes its declaredIn or in directly instead of calling the morph fallback, so a configured morph handler doesn't apply to an input schema. An index key's morph likewise skips the fallback. - With io "in", `"+": "delete"` no longer writes additionalProperties: false, or the propertyNames/additionalProperties pair of a lone index signature, since the input may have the keys delete removes. "reject" still does. `output` and toJsonSchema() don't set io and are unchanged, and precompiled validators bake `~standard.jsonSchema` by calling it, so they bake the new input schema. The tests are #1695's, adapted to this branch's API. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
ssalbdivad
added a commit
that referenced
this pull request
Nov 9, 2026
…uthors Each fix below landed on featherduster from a port or an independent fix, but each started from a reasonable community PR against 2.x, and the CHANGELOG thanks every contributor whose work this release supersedes: - #1721 (@RaphaelFakhri): fast-check keeps a regex's flags (#1720) - #1722 (@louisss1016): Temporal values survive a morph / deepClone (#1719) - #1725 (@RClaudiuM): an undefined discriminant case checks its key (#1724) - #1715 (@SynthLuvr): ~standard.jsonSchema.input drops undefined (#1462); only its input half was taken, output keeps routing to fallback.unit #1718 is not credited: 3.0 answers #1469 with jsonSchema meta rather than its bare pattern key. #1705 and #1695 were already thanked. Also notes that a cyclic index signature with no way out now generates shrinking dictionaries instead of overflowing the stack (6f4dd5d).
Draft
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #1575
~standard.jsonSchema.input()convertedthis.rawIn, andOptionalNode.rawIn(like thedefaultablesreduceIo for tuples) drops the default, so a type likeproduced
{ properties: { firstName: { type: "string" } } }with nodefault, even thoughtoJsonSchema()on the same type includes it. Zod and Valibot both includedefaultin their input schemas, and for input it is where JSON Schema'sdefaultannotation applies (the key may be omitted and the default is used).The input schema now converts the type itself with a new internal
io: "in"on the JSON Schema context, which keepsrawIn's behavior in the two places where converting the full type would differ:declaredIn ?? in) directly instead of going through themorphfallback, so a configuredmorphfallback still isn't used for input (as before, sincerawInhad no morphs), and a default inside a morph's input is keptonUndeclaredKey("delete")doesn't addadditionalProperties: false, since those keys are allowed on inputDefaults that aren't JSON still go through the
defaultValuefallback, which the standard converter already maps to omitting them.I avoided keeping the default on
rawInitself (e.g. as meta on the input prop) because that changesT.in's hash, soT.in.equals(type({ "a?": "string" }))would become false.One cosmetic difference I noticed: for a union whose
truebranch is a morph, e.g.type("true").pipe(() => 1).or("false"), the input schema is now{ enum: [true, false] }rather than{ type: "boolean" }(the boolean grouping only matches unit branches). Happy to special-case that if you'd prefer.Tests
Added to
ark/type/__tests__/standardSchema.test.ts:string.numeric.parse = '1') appear in the input schemaonUndeclaredKey("delete")allows undeclared keys in the input schema but not the outputmorphfallback isn't used for the input schemaThe first two fail on
mainand pass with this change; the last two pass on both and guard therawInparity.What was run locally:
pnpm testFiles ark/type/__tests__/standardSchema.test.ts(with type assertions): 17 passingpnpm test: 1795 passingpnpm typecheckRepo: no errorsprettier --checkandeslinton the changed files: cleanNot run: the full
pnpm prChecks(buildRepo, benches,testV8,testIntegration,testTsVersions,testTypedLoose).